//
//  GameplayState.m
//  GLSprite
//
//  Created by Daniel Polak on 7/19/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "GameplayState.h"
#import "GameplayManager.h"
#import "Mind.h"

#import "String.h"
#import "ParticleEmitter.h"

@implementation GameplayState

- (void)Enter {
	//Create strings
	[self SetupStrings];
	
	//setup backgrounds
	[self SetupBackgrounds];
	
	//import all data from text files
	///force create all objects in level
	[self SetupLevel];
	
	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

	
}

- (void)Update {
	[[GameplayManager gameplayManager] UpdateGame];

	Mind* myMind = [Mind mind];

	if (myMind.tap) {
		//Move totoro
		CGPoint myLocation = [[myMind tap] tapLocation];
		[myMind setSpriteVerts:myLocation];
		
		//Create a particle Emitter
		ParticleEmitter* myEmitter = [[ParticleEmitter alloc] init];
		[myEmitter Create:5 :0.5f :myLocation];
		[[myMind vParticleEmitters] push:myEmitter];
	}
}

- (void)Exit {
	//clean out strings
	[self CleanupStrings];
	//clean out backgrounds
	[self CleanupBackgrounds];
	//clean out level data
	[self CleanupLevel];
}

- (void)Render {
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

- (void)SetupStrings {
	String* pString = [[String alloc] init];
	for (int i = 0; i < 4; ++i) {
		[pString SetString:i];
		[[[Mind mind] vStrings] push:pString];
	}
}

- (void)SetupBackgrounds {
	
}

- (void)SetupLevel {
	//TODO //Load individual level data from files
	//Force create level data
}

- (void)CleanupStrings {
	for (int i = 0; i < 4; ++i) {
		[[[Mind mind] vStrings] pop];
	}
}

- (void)CleanupBackgrounds {
	
}

- (void)CleanupLevel {
	
}

@end
